package cn.bdqn.pn.service.base.impl;

import cn.bdqn.pn.pojo.base.Img;
import cn.bdqn.pn.reposity.base.ImageRepository;
import cn.bdqn.pn.service.base.ImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

@Service("imgService")
public class ImgServiceImpl implements ImgService {

    @Autowired
    private ImageRepository imageRepository;

    /**
     * 增加
     * @param img
     * @return
     * @throws SQLException
     */
    @Override
    public boolean addImgInfo(Img img) throws SQLException {
        Img img1=imageRepository.save(img);
        if(img1!=null){
            return true;
        }else{
            return false;
        }

    }

    /**
     * 查询图片信息
     * @param imgTypeId
     * @param releId
     * @return
     * @throws SQLException
     */
    @Override
    public Img findByImgInfo(Integer imgTypeId, Integer releId) throws SQLException {
        return imageRepository.findAllByReleidAndImgtypeid(imgTypeId,releId);
    }

    /**
     * 根据供应商Id查询图片信息
     * @param releId
     * @return
     * @throws SQLException
     */
    @Override
    public Img findByReleId(Integer releId) throws SQLException {
        return imageRepository.findImgByReleid(releId);
    }

    /**
     * --cp
     * 根据商品id和图片类型Id查询图片信息
     * @param releid
     * @return
     */
    @Override
    public Img findImgByReleidAndImgtypeid(Integer releid, Integer imgtypeid) {
        return imageRepository.findImgByReleidAndImgtypeid(releid,imgtypeid);
    }




}
